package cn.yanhu.kuwanapp.home.adapter

import android.content.Context
import cn.woochen.comlib.adapter.CommonRecyclerAdapter
import cn.woochen.comlib.util.ext.setOnSingleClickListener
import cn.yanhu.kuwanapp.R
import cn.yanhu.kuwanapp.bean.response.RespCarouselBean
import cn.yanhu.kuwanapp.databinding.ItemHomeRewardBinding
import cn.yanhu.kuwanapp.databinding.ItemTopMenuBinding

/**
 *
 * 类描述：
 * @author：woochen
 * create at：2021/7/28 7:19 AM
 */
class HomeRewardAdapter(datas: List<RespCarouselBean.InnerBean>) :
        CommonRecyclerAdapter<RespCarouselBean.InnerBean>(datas, R.layout.item_home_reward) {

    var mOperateListener:OperateListener?=null
    interface OperateListener{
        fun click(position: Int)
    }

    override fun convert(holder: ViewHolder, item: RespCarouselBean.InnerBean) {
        holder.getDataBinding<ItemHomeRewardBinding?>()?.let {
            it.itemBean = item
            it.cllRoot.setOnSingleClickListener {
                val newPosition = holder.layoutPosition % mDatas.size
                mOperateListener?.click(newPosition)
            }
        }
    }

    override fun getItem(position: Int): RespCarouselBean.InnerBean {
        val newPosition = position % mDatas.size
        return mDatas[newPosition]
    }

    override fun getItemCount(): Int {
        return if (mDatas.isEmpty()) 0 else Integer.MAX_VALUE
    }
}